<?php

/**
 * TransactionInitiationRequest.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for Amazon Seller Wallet Open Banking API.
 *
 * The Selling Partner API for Seller Wallet (Seller Wallet API) provides financial information that is relevant to a seller's Seller Wallet account. You can obtain financial events, balances, and transfer schedules for Seller Wallet accounts. You can also schedule and initiate transactions.
 *
 * The version of the OpenAPI document: 2024-03-01
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\sellerWallet\v2024_03_01;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * TransactionInitiationRequest Class Doc Comment.
 *
 * @category Class
 *
 * @description Request body to initiate a transaction from a SW bank account to another customer defined bank account
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class TransactionInitiationRequest implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'TransactionInitiationRequest';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'source_account_id' => 'string',
        'destination_account_id' => 'string',
        'description' => 'string',
        'destination_transaction_instrument' => '\SpApi\Model\sellerWallet\v2024_03_01\TransactionInstrumentDetails',
        'destination_account_holder_address' => '\SpApi\Model\sellerWallet\v2024_03_01\AccountHolderAddress',
        'source_amount' => '\SpApi\Model\sellerWallet\v2024_03_01\Currency',
        'transfer_rate_details' => '\SpApi\Model\sellerWallet\v2024_03_01\TransferRatePreview',
        'request_time' => '\DateTime'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'source_account_id' => null,
        'destination_account_id' => null,
        'description' => null,
        'destination_transaction_instrument' => null,
        'destination_account_holder_address' => null,
        'source_amount' => null,
        'transfer_rate_details' => null,
        'request_time' => 'date-time'];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'source_account_id' => false,
        'destination_account_id' => true,
        'description' => false,
        'destination_transaction_instrument' => false,
        'destination_account_holder_address' => true,
        'source_amount' => false,
        'transfer_rate_details' => true,
        'request_time' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'source_account_id' => 'sourceAccountId',
        'destination_account_id' => 'destinationAccountId',
        'description' => 'description',
        'destination_transaction_instrument' => 'destinationTransactionInstrument',
        'destination_account_holder_address' => 'destinationAccountHolderAddress',
        'source_amount' => 'sourceAmount',
        'transfer_rate_details' => 'transferRateDetails',
        'request_time' => 'requestTime',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'source_account_id' => 'setSourceAccountId',
        'destination_account_id' => 'setDestinationAccountId',
        'description' => 'setDescription',
        'destination_transaction_instrument' => 'setDestinationTransactionInstrument',
        'destination_account_holder_address' => 'setDestinationAccountHolderAddress',
        'source_amount' => 'setSourceAmount',
        'transfer_rate_details' => 'setTransferRateDetails',
        'request_time' => 'setRequestTime',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'source_account_id' => 'getSourceAccountId',
        'destination_account_id' => 'getDestinationAccountId',
        'description' => 'getDescription',
        'destination_transaction_instrument' => 'getDestinationTransactionInstrument',
        'destination_account_holder_address' => 'getDestinationAccountHolderAddress',
        'source_amount' => 'getSourceAmount',
        'transfer_rate_details' => 'getTransferRateDetails',
        'request_time' => 'getRequestTime',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('source_account_id', $data ?? [], null);
        $this->setIfExists('destination_account_id', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('destination_transaction_instrument', $data ?? [], null);
        $this->setIfExists('destination_account_holder_address', $data ?? [], null);
        $this->setIfExists('source_amount', $data ?? [], null);
        $this->setIfExists('transfer_rate_details', $data ?? [], null);
        $this->setIfExists('request_time', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['source_account_id']) {
            $invalidProperties[] = "'source_account_id' can't be null";
        }
        if (null === $this->container['description']) {
            $invalidProperties[] = "'description' can't be null";
        }
        if (null === $this->container['destination_transaction_instrument']) {
            $invalidProperties[] = "'destination_transaction_instrument' can't be null";
        }
        if (null === $this->container['source_amount']) {
            $invalidProperties[] = "'source_amount' can't be null";
        }
        if (null === $this->container['request_time']) {
            $invalidProperties[] = "'request_time' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets source_account_id.
     */
    public function getSourceAccountId(): string
    {
        return $this->container['source_account_id'];
    }

    /**
     * Sets source_account_id.
     *
     * @param string $source_account_id The unique identifier of the source Amazon SW bank account from where the money needs to be debited
     */
    public function setSourceAccountId(string $source_account_id): self
    {
        if (is_null($source_account_id)) {
            throw new \InvalidArgumentException('non-nullable source_account_id cannot be null');
        }
        $this->container['source_account_id'] = $source_account_id;

        return $this;
    }

    /**
     * Gets destination_account_id.
     */
    public function getDestinationAccountId(): ?string
    {
        return $this->container['destination_account_id'];
    }

    /**
     * Sets destination_account_id.
     *
     * @param null|string $destination_account_id Optional field to specify the unique identifier of the destination bank account where the money needs to be deposited
     */
    public function setDestinationAccountId(?string $destination_account_id): self
    {
        if (is_null($destination_account_id)) {
            array_push($this->openAPINullablesSetToNull, 'destination_account_id');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('destination_account_id', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['destination_account_id'] = $destination_account_id;

        return $this;
    }

    /**
     * Gets description.
     */
    public function getDescription(): string
    {
        return $this->container['description'];
    }

    /**
     * Sets description.
     *
     * @param string $description Optional field to specify description for the transaction
     */
    public function setDescription(string $description): self
    {
        if (is_null($description)) {
            throw new \InvalidArgumentException('non-nullable description cannot be null');
        }
        $this->container['description'] = $description;

        return $this;
    }

    /**
     * Gets destination_transaction_instrument.
     */
    public function getDestinationTransactionInstrument(): TransactionInstrumentDetails
    {
        return $this->container['destination_transaction_instrument'];
    }

    /**
     * Sets destination_transaction_instrument.
     *
     * @param TransactionInstrumentDetails $destination_transaction_instrument destination_transaction_instrument
     */
    public function setDestinationTransactionInstrument(TransactionInstrumentDetails $destination_transaction_instrument): self
    {
        if (is_null($destination_transaction_instrument)) {
            throw new \InvalidArgumentException('non-nullable destination_transaction_instrument cannot be null');
        }
        $this->container['destination_transaction_instrument'] = $destination_transaction_instrument;

        return $this;
    }

    /**
     * Gets destination_account_holder_address.
     */
    public function getDestinationAccountHolderAddress(): ?AccountHolderAddress
    {
        return $this->container['destination_account_holder_address'];
    }

    /**
     * Sets destination_account_holder_address.
     *
     * @param null|AccountHolderAddress $destination_account_holder_address destination_account_holder_address
     */
    public function setDestinationAccountHolderAddress(?AccountHolderAddress $destination_account_holder_address): self
    {
        if (is_null($destination_account_holder_address)) {
            array_push($this->openAPINullablesSetToNull, 'destination_account_holder_address');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('destination_account_holder_address', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['destination_account_holder_address'] = $destination_account_holder_address;

        return $this;
    }

    /**
     * Gets source_amount.
     */
    public function getSourceAmount(): Currency
    {
        return $this->container['source_amount'];
    }

    /**
     * Sets source_amount.
     *
     * @param Currency $source_amount source_amount
     */
    public function setSourceAmount(Currency $source_amount): self
    {
        if (is_null($source_amount)) {
            throw new \InvalidArgumentException('non-nullable source_amount cannot be null');
        }
        $this->container['source_amount'] = $source_amount;

        return $this;
    }

    /**
     * Gets transfer_rate_details.
     */
    public function getTransferRateDetails(): ?TransferRatePreview
    {
        return $this->container['transfer_rate_details'];
    }

    /**
     * Sets transfer_rate_details.
     *
     * @param null|TransferRatePreview $transfer_rate_details transfer_rate_details
     */
    public function setTransferRateDetails(?TransferRatePreview $transfer_rate_details): self
    {
        if (is_null($transfer_rate_details)) {
            array_push($this->openAPINullablesSetToNull, 'transfer_rate_details');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('transfer_rate_details', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['transfer_rate_details'] = $transfer_rate_details;

        return $this;
    }

    /**
     * Gets request_time.
     */
    public function getRequestTime(): \DateTime
    {
        return $this->container['request_time'];
    }

    /**
     * Sets request_time.
     *
     * @param \DateTime $request_time The transaction initiation request time in date-time format
     */
    public function setRequestTime(\DateTime $request_time): self
    {
        if (is_null($request_time)) {
            throw new \InvalidArgumentException('non-nullable request_time cannot be null');
        }
        $this->container['request_time'] = $request_time;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
